/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.ResultSet;
import java.util.ArrayList;
import pojo.DanhMuc_pojo;
import util.MySQLDataAccessHelper;

/**
 *
 * @author Rocker000
 */
public class DanhMuc_dao 
{   
    public static ArrayList<DanhMuc_pojo> LayDanhSach()
    {
        ArrayList<DanhMuc_pojo> ds = new ArrayList<DanhMuc_pojo>();
        try
        {            
            String sql ="select*from danhmuc";
            MySQLDataAccessHelper helper = new MySQLDataAccessHelper();
            helper.Open();
            ResultSet rs = helper.ExeCuteQuery(sql);
            while(rs.next())
            {
                DanhMuc_pojo temp = new DanhMuc_pojo();
                temp.setMaDanhMuc(rs.getString("MaDanhMuc"));
                temp.setTenDanhMuc(rs.getString("TenDanhMuc"));
                ds.add(temp);
            }
            helper.Close();
                
        }
        catch(Exception ex)
        {
            System.out.println(ex.getMessage());
        }
        return ds;        
    }
    public static DanhMuc_pojo LayDanhMuc(String madanhmuc)
    {
        DanhMuc_pojo dm = new DanhMuc_pojo();
        String sql = "select*from danhmuc where madanhmuc='"+madanhmuc+"'";
        try
        {
            MySQLDataAccessHelper helper = new MySQLDataAccessHelper();
            helper.Open();
            ResultSet rs = helper.ExeCuteQuery(sql);
            while(rs.next())
            {
                dm.setMaDanhMuc(rs.getString("madanhmuc"));
                dm.setTenDanhMuc(rs.getString("tendanhmuc"));
            }
            helper.Close();
        }
        catch(Exception ex)
        {
            System.out.println(ex.getMessage());
        }
        return dm;
                
    }
        
    
    
            
          
}